<?php
include_once('common/header.php');
if($AppUI->id <= 0 || (isset($_SESSION['seo']) && (($_SESSION['seo']&1<<1) == 0)) || $AppUI->type < 2) {
	$this->_redirect(HOST_BACKEND);
}
$intLanguage	= $objRequest->getParam('planguage', LANGUAGE_VN);
$strController	= $objRequest->getParam('pcontroller', '');
$strAction		= $objRequest->getParam('paction', '');
$strName		= $objRequest->getParam('pname', '');
$strTitle		= $objRequest->getParam('ptitle', '');
$strKeywords	= $objRequest->getParam('pkeywords', '');
$strDescription	= $objRequest->getParam('pdescription', '');
$intError		= 0;
if($strController == '') $intError = 3;
elseif($strController != '' && !Ecore_Function::isValidCode($strController)) $intError = 4;
elseif($strAction == '') $intError = 5;
elseif($strAction != '' && !Ecore_Function::isValidCode($strAction)) $intError = 6;
elseif($strName == '') $intError = 7;
elseif($strName != '' && strlen(Ecore_Function::stripTags($strName,-2)) < 5) $intError = 8;
elseif($strTitle == '') $intError = 9;
elseif($strKeywords == '') $intError = 10;
elseif($strDescription == '') $intError = 11;
if($intError == 0) {
	if(isset($_SESSION['post'])) unset($_SESSION['post']);
	if(isset($_SESSION['serr'])) unset($_SESSION['serr']);
	$objSeo 	= new Seo();
	$intError	= $objSeo->add($AppUI->id, $strController, $strAction, Ecore_Function::stripTags($strName,-2), $strTitle, $strKeywords, $strDescription,$intLanguage);
	if($intError == 0) {
		Ecore_Function::setMsg($arrMessage[1]);
		$this->_redirect(HOST_BACKEND . 'seo/index');
	}
}
if($intError > 0) {
	$_SESSION['post']	= $objRequest->getParams();
	$_SESSION['serr']	= $arrError[$intError];
	$this->_redirect(HOST_BACKEND . 'seo/add');
}